package com.kaiwukj.android.ufamily.utils

import android.content.Context
import android.view.View
import android.widget.TextView
import com.afollestad.materialdialogs.LayoutMode
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.customview.getCustomView
import com.kaiwukj.android.ufamily.R
import org.jetbrains.annotations.NotNull

/**
 * 帖子屏蔽
 */
fun showBottomReportDialog(context: @NotNull Context, onClick: @NotNull View.OnClickListener, isMine: Boolean): MaterialDialog {
    val dialog = MaterialDialog(context, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
        customView(R.layout.dialog_post_card_detail_report, noVerticalPadding = true)
    }
    val customView = dialog.getCustomView()
    customView.findViewById<TextView>(R.id.tv_cancel_report).setOnClickListener {
        dialog.dismiss()
    }
    customView.findViewById<TextView>(R.id.tv_block_this_content).setOnClickListener(onClick)
    customView.findViewById<TextView>(R.id.tv_block_this_user).setOnClickListener(onClick)
    customView.findViewById<TextView>(R.id.tv_report_this_user).setOnClickListener(onClick)
    customView.findViewById<TextView>(R.id.tv_delete).setOnClickListener(onClick)
    if (isMine) {
        customView.findViewById<TextView>(R.id.tv_delete).visibility = View.VISIBLE
        customView.findViewById<TextView>(R.id.tv_block_this_content).visibility = View.GONE
        customView.findViewById<TextView>(R.id.tv_block_this_user).visibility = View.GONE
        customView.findViewById<TextView>(R.id.tv_report_this_user).visibility = View.GONE
    }
    return dialog
}

/**
 * 个人屏蔽
 */
fun showBottomReportDialog(context: @NotNull Context, onClick: @NotNull View.OnClickListener): MaterialDialog {
    val dialog = MaterialDialog(context, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
        customView(R.layout.dialog_post_card_detail_report, noVerticalPadding = true)
    }
    val customView = dialog.getCustomView()
    customView.findViewById<TextView>(R.id.tv_cancel_report).setOnClickListener {
        dialog.dismiss()
    }
    customView.findViewById<TextView>(R.id.tv_block_this_content).setOnClickListener(onClick)
    customView.findViewById<TextView>(R.id.tv_block_this_user).setOnClickListener(onClick)
    customView.findViewById<TextView>(R.id.tv_report_this_user).setOnClickListener(onClick)
    customView.findViewById<TextView>(R.id.tv_delete).setOnClickListener(onClick)
    customView.findViewById<TextView>(R.id.tv_delete).visibility = View.GONE
    customView.findViewById<TextView>(R.id.tv_block_this_content).visibility = View.GONE
    customView.findViewById<TextView>(R.id.tv_block_this_user).visibility = View.VISIBLE
    customView.findViewById<TextView>(R.id.tv_report_this_user).visibility = View.GONE
    return dialog
}